<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class GoodsSpecificationSku extends Model {

    use SoftDelete;

    // 表名
    protected $name = 'goods_specification_sku';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    /**
     * 通过规格获取商品信息
     * @author
     */
    public function getCartGoodsList($spec_ids) {


        $list = [];
        $num=0;
        foreach ($spec_ids as $k => $v) {
            $goodsInfo=static::alias('a')->join('goods b', 'a.goods_id=b.id', 'LEFT')
                //   ->join('cmf_country_manager c', 'b.country_id=c.id', 'LEFT')
                ->field('a.*,b.name  as goods_name,b.thumbnail_image,b.merchant_id')
                ->where('a.id', '=', $v)
                // ->where('b.status','=','2')
                ->whereNull('b.deletetime')
                ->find();
            if ($goodsInfo){
                $list[$num] = $goodsInfo;
                $num++;
            }
        }
        $list=toArray($list);
        return $list;
    }

    /**
     * 通过规格获取商品信息
     * @author
     */
    public function getGoodsList($spec_ids) {

        $list = static::alias('a')->join('goods b', 'a.goods_id=b.id', 'LEFT')
            //   ->join('cmf_country_manager c', 'b.country_id=c.id', 'LEFT')
            ->field('a.*,b.name  as goods_name,b.thumbnail_image,b.status,b.deletetime as is_del,b.is_ship,b.freight_type,b.freight_id')->whereIn('a.id', $spec_ids)->select();

        return $list;
    }

}
